﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace GabageFactory.Models
{
    public class PiezometerReposity : Reposity
    {
        public IEnumerable<Piezometer_well_base_info> ListWell(int stackId)
        {
            var wells = from d in _dataContext.Piezometer_well_base_infos
                        where d.Stack_id == stackId
                            select d;
            foreach (Piezometer_well_base_info d in wells)
            {
                yield return d;
            }
        }

        public Piezometer_well_base_info GetWellById(int id, int piezometerId)
        {
            var well = from d in _dataContext.Piezometer_well_base_infos
                          where id == d.Stack_id && d.piezometer_well_id == piezometerId
                          select d;
            if (well != null && well.Count() > 0)
            {
                return well.First();
            }
            else
            {
                return null;
            }
        }

        public Piezometer_well_base_info CreatePiezometerWell(Piezometer_well_base_info well)
        {
            _dataContext.Piezometer_well_base_infos.InsertOnSubmit(well);
            SubmitChanges();
            return well;
        }

        public void DeleteWells(int stackId)
        {
            var wells = from s in _dataContext.Piezometer_well_base_infos
                          where s.Stack_id == stackId
                          select s;

            foreach (Piezometer_well_base_info well in wells)
            {
                _dataContext.Piezometer_well_base_infos.DeleteOnSubmit(well);
            }
            SubmitChanges();
        }

        public IEnumerable<Piezometer_base_info> ListEquaps(int stackId)
        {
            var equaps = from d in _dataContext.Piezometer_base_infos
                        where d.Stack_id == stackId
                        select d;
            foreach (Piezometer_base_info d in equaps)
            {
                yield return d;
            }
        }

        public Piezometer_base_info GetEquapById(int id, int piezometerId)
        {
            var well = from d in _dataContext.Piezometer_base_infos
                       where id == d.Stack_id && d.piezometer_id == piezometerId
                       select d;
            if (well != null && well.Count() > 0)
            {
                return well.First();
            }
            else
            {
                return null;
            }
        }

        public Piezometer_base_info CreatePiezometerEquap(Piezometer_base_info equap)
        {
            _dataContext.Piezometer_base_infos.InsertOnSubmit(equap);
            SubmitChanges();
            return equap;
        }

        public void DeleteEquaps(int stackId)
        {
            var equaps = from s in _dataContext.Piezometer_base_infos
                        where s.Stack_id == stackId
                        select s;

            foreach (Piezometer_base_info equap in equaps)
            {
                _dataContext.Piezometer_base_infos.DeleteOnSubmit(equap);
            }
            SubmitChanges();
        }
    }
}